package me.leiusual.sharing.ui.shop

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.repository.StoreRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class ShopApplyViewModel @Inject constructor(
    private val storeRepository: StoreRepository
) : ViewModel() {

  // 创建店铺

  private val _storeApply = MutableLiveData<String>()
  val storeApply: LiveData<Data<Unit>> = switchMap(_storeApply) {
    storeRepository.storeApply(it).toLiveData()
  }

  fun storeApply(name: String) {
    _storeApply.value = name
  }
}